using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using System.Data;

namespace LiveStock.dataAccess
{
    /// <summary>
    /// Data Access Layer class for EvaluationSources table
    /// </summary>
    class EvaluationSourcesData
    {
        private EvaluationSourcesData() { }

        public static int EvaluationSourceUpdateByID(EvaluationSources.EvaluationSourcesRow esr)
        {
            int ar = 0;
            using (SqlCommand cmd = DBManager.GetCommand("EvaluationSourceUpdateByID"))
            {
                cmd.Parameters.AddWithValue("EvaluationSourceID", esr.EvaluationSourceID);
                cmd.Parameters.AddWithValue("SourceName", esr.Name);
                cmd.Parameters.AddWithValue("URL", esr.URL);
                ar = DBManager.ExecuteNonQuery(cmd);
            }
            return ar;
        }

        public static EvaluationSources.EvaluationSourcesDataTable EvaluationSourcesGetAll()
        {
            EvaluationSources.EvaluationSourcesDataTable esdt = new EvaluationSources.EvaluationSourcesDataTable();
            using (SqlCommand cmd = DBManager.GetCommand("EvaluationSourcesGetAll"))
            {
                DBManager.FillDataTable(esdt, cmd);
            }
            return esdt;
        }

        public static int EvaluationSourceInsert(EvaluationSources.EvaluationSourcesRow esr)
        {
            int ar = 0;
            using (SqlCommand cmd = DBManager.GetCommand("EvaluationSourceInsert"))
            {
                cmd.Parameters.AddWithValue("SourceName", esr.Name);
                cmd.Parameters.AddWithValue("URL", esr.URL);
                ar = DBManager.ExecuteNonQuery(cmd);
            }
            return ar;
        }

        public static EvaluationSources.EvaluationSourcesDataTable EvaluationSourceGetByID(int evaluationSourceID)
        {
            EvaluationSources.EvaluationSourcesDataTable esdt = new EvaluationSources.EvaluationSourcesDataTable();
            using (SqlCommand cmd = DBManager.GetCommand("EvaluationSourceGetByID"))
            {
                cmd.Parameters.AddWithValue("EvaluationSourceID", evaluationSourceID);
                DBManager.FillDataTable(esdt, cmd);
            }
            return esdt;
        }

        public static int EvaluationSourceDeleteByID(int evaluationSourceID)
        {
            int ar = 0;
            using (SqlCommand cmd = DBManager.GetCommand("EvaluationSourceDeleteByID"))
            {
                cmd.Parameters.AddWithValue("EvaluationSourceID", evaluationSourceID);
                ar = DBManager.ExecuteNonQuery(cmd);
            }
            return ar;
        }

        public static EvaluationSources.EvaluationSourcesDataTable EvaluationSourceGetByName(string name)
        {
            EvaluationSources.EvaluationSourcesDataTable esdt = new EvaluationSources.EvaluationSourcesDataTable();
            using (SqlCommand cmd = DBManager.GetCommand("EvaluationSourceGetByName"))
            {
                cmd.Parameters.AddWithValue("@Name", name);
                DBManager.FillDataTable(esdt, cmd);
            }
            return esdt;
        }
    }
}

